1 <?php
2 session_start();
3 include(
"header.php");
4 include(
"sidebar.php");
5 include(
"dbconnection.php");
6 ?>
7 <script type=
"text/javascript">
8 function isNumberKey(evt)
9       {
10
11          
var charCode = (evt.which) ? evt.which : event.keyCode
12         
//alert(charCode);
13          
if (charCode > 63 && charCode < 92 )
14          {
15          
return true;
16      }
17      
else if (charCode > 96 && charCode < 123 )
18          {
19          
return true;
20      }
21      
else
22      {
23                              alert(
"should be alphabet");
24         
return false;
25      }
26      }
27 function validate()
28 {

29 if
(document.form1.sparename.value=="")
30 {
31     alert(
"Enter Sparepart Name");
32     document.form1.sparename.focus();
33     
return false;
34 }

35 if
(document.form1.sparetype.value=="")
36 {
37     alert(
"Enter Sparepart Type");
38     document.form1.sparetype.focus();
39     
return false;
40 }

41 if
(document.form1.spareno.value=="")
42 {
43     alert(
"Enter Sparepart Number");
44     document.form1.spareno.focus();
45     
return false;
46 }

47 if
(document.form1.sparecost.value=="")
48 {
49     alert(
"Enter Sparepart Cost");
50     document.form1.sparecost.focus();
51     
return false;
52 }

53 if
(document.form1.description.value=="")
54 {
55     alert(
"Enter Sparepart Description");
56     document.form1.description.focus();
57     
return false;
58 }
59
60 }
61 </script>
62 <?php

63 if
(isset($_POST["submit"]))
64 {
65 move_uploaded_file($_FILES[
"file"]["tmp_name"],
66 "upload/"
. $_FILES["file"]["name"]);
67 $img = $_FILES[
"file"]["name"];
68 $sql =
"insert into spareparts(name,type,cost,sparepartno,description,image) values('$_POST[sparename]','$_POST[sparetype]','$_POST[sparecost]','$_POST[spareno]','$_POST[description]','$img')";
69 $ctins =
1;
70 if
(!mysql_query($sql,$con))
71   {
72   die(
'Error: ' . mysql_error());
73   }
74 }

75 if
(isset($_POST["update"]))
76 {
77 move_uploaded_file($_FILES[
"file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);
78 $img = $_FILES[
"file"]["name"];
79 if
($img=="")
80 {
81 $sql =
"update spareparts set name='$_POST[sparename]',type='$_POST[sparetype]',cost='$_POST[sparecost]',sparepartno='$_POST[spareno]',description='$_POST[description]' where spid='$_GET[sparepartid]'";
82 }

83 else

84 {
85 $sql =
"update spareparts set name='$_POST[sparename]',type='$_POST[sparetype]',cost='$_POST[sparecost]',sparepartno='$_POST[spareno]',description='$_POST[description]',image='$img' where spid='$_GET[sparepartid]'";
86 }
87 $ctins =
1;
88 if
(!mysql_query($sql,$con))
89   {
90   die(
'Error: ' . mysql_error());
91   }
92 }
93
94
95 ?>
96 <?php
97 $sql = mysql_query(
"select * from spareparts where spid = '$_GET[sparepartid]'");
98 $row = mysql_fetch_array($sql);
99 ?>
100
101 <?php

102 if
($ctins == 1)
103 {
104     
if(isset($_GET['sparepartid'])){
105     echo
"<center><b>Spare Parts Updated Successfully...</b></center><br>";
106     }
107     
else
108     {
109     echo
"<center><b>Spare Parts Added Successfully...</b></center><br>";
110     }
111 }

112 else

113 {
114 ?>
115         
116                             
117         <div id=
"main">
118             
119             <a name=
"TemplateInfo"></a>
120             <h1>Add spare parts</h1>
121             <h3><center><a href=
"viewspareparts.php">View spare parts</a></center></h3>
122         <form id=
"form1" name="form1" method="post" action="" enctype="multipart/form-data" onsubmit="return validate()">
123             <table width=
"489" border="0">
124               <tr>
125                 <th width=
"169" height="33" scope="row">Sparepart Name</th>
126                 <td width=
"140">
127                   <label
for="fname"></label>
128                   <label
for="custname"></label>
129                   <label
for="sparename"></label>
130                 <input name=
"sparename" type="text" value="<?php echo $row['name']; ?>" id="sparename" size="30" onKeyPress="return isNumberKey(event)"/></td>
131               </tr>
132               <tr>
133                 <th height=
"37" scope="row">Sparepart Type
134                   <label
for="lname"></label></th>
135                 <td><label
for="vehname"></label>
136                   <label
for="sparetype"></label>
137                 <input name=
"sparetype" type="text" value="<?php echo $row['type']; ?>" id="sparetype" size="30" /></td>
138               </tr>
139               <tr>
140                 <th height=
"36" scope="row">Sparepart No</th>
141                 <td>
142                   <input name=
"spareno" type="text" value="<?php echo $row['sparepartno']; ?>" id="spareno" size="30" />
143                </td>
144               </tr>
145               <tr>
146                 <th height=
"37" scope="row">Sparepart Cost
147                   <label
for="lname"></label></th>
148                 <td><label
for="vehname"></label>
149                   <label
for="sparecost"></label>
150                 <input type=
"text" name="sparecost" value="<?php echo $row['cost']; ?>" id="sparecost" size="30" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;"/></td>
151               </tr>
152               <tr>
153                 <th height=
"34" scope="row">Description </th>
154                 <td><label
for="password"></label>
155                   <label
for="date"></label>
156                   <label
for="description"></label>
157                 <textarea name=
"description" id="description"><?php echo $row['description']; ?></textarea></td>
158               </tr>
159               <tr>
160                 <th height=
"40" scope="row">Image</th>
161                 <td><label
for="confpass"></label>
162                   <label
for="images"></label>
163                   <label
for="address"></label>
164                   <label
for="image"></label>
165                 <input type=
"file" name="file" id="file" />
166                 <br />
167                 <?php
168                 
if(isset($_GET['sparepartid']))
169                 {
170                 ?>
171 <img src=
"upload/<?php echo $row['image']; ?>" width="150" height="150" />
172                 <?php
173                 }
174                 ?></td>
175               </tr>
176               <tr>
177                 <th scope=
"row">&nbsp;</th>
178                 <td><?php
if(isset($_GET['sparepartid'])) { ?><input type="submit" name="update" id="submit" value="Update Spare parts" /> <?php } else { ?> <input type="submit" name="submit" id="submit" value="Submit" /><?php } ?></td>
179               </tr>
180               <tr>
181                 <th scope=
"row">&nbsp;</th>
182                 <td>&nbsp;</td>
183               </tr>
184           </table>
185       </form>
186       <?php
187       }
188       ?>
189             <p>&nbsp;</p>
190                                     
191         </div>
192         
193 <!-- wrap ends here -->
194 </div>
195         
196 <?php
197 include(
"footer.php");
198 ?>


Gõ tìm kiếm nhanh...